package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.service.MessageCenterService;
import com.ruoyi.system.tools.BooleanMessage;
import com.ruoyi.web.controller.tool.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/system/messagecenter")
public class MessageCenterController {

    @Autowired
    private MessageCenterService ddService;

    @GetMapping("custommessage")
    public String custommessage()
    {
        return "system/messagecenter/custommessage";
    }

    /**
     *
     * @description	自定义发送短信 批量
     */
    @PostMapping("send_piliang")
    @ResponseBody
//    @DataSource(value = DataSourceType.SLAVE)
    public JsonResult<?> send_piliang(@RequestParam("messagecontent") String ppMessageContent,
                                      @RequestParam("phones") String ppPhones,
                                      HttpServletRequest request){
        try {

            // 获取电话集合
            ppMessageContent = ppMessageContent.trim();
            ppPhones = ppPhones.trim();
            String[] phones =ppPhones.split(",");

            BooleanMessage mmBooleanMessage = ddService.send_piliang(phones, ppMessageContent);
            if(!mmBooleanMessage.isOk()) {
                return JsonResult.getErrorResult(mmBooleanMessage.getMessage().toString());
            }

            return JsonResult.getSuccessResult("发送成功");

        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.getErrorResult("自定义短信发送失败");
        }
    }
}
